<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  

  
  <title>linux 编译安装opencv | 进击的菜鸟</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="Linux 编译OpenCV安装 安装类库sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev  sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev">
<meta name="keywords" content="linux">
<meta property="og:type" content="article">
<meta property="og:title" content="linux 编译安装opencv">
<meta property="og:url" content="http://yoursite.com/2019/07/16/linux-编译安装opencv/index.html">
<meta property="og:site_name" content="进击的菜鸟">
<meta property="og:description" content="Linux 编译OpenCV安装 安装类库sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev  sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-07-19T01:23:28.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="linux 编译安装opencv">
<meta name="twitter:description" content="Linux 编译OpenCV安装 安装类库sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev  sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev">
  
    <link rel="alternate" href="/atom.xml" title="进击的菜鸟" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">进击的菜鸟</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="搜索"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-linux-编译安装opencv" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2019/07/16/linux-编译安装opencv/" class="article-date">
  <time datetime="2019-07-16T03:54:58.000Z" itemprop="datePublished">2019-07-16</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/随笔/">随笔</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      linux 编译安装opencv
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Linux-编译OpenCV"><a href="#Linux-编译OpenCV" class="headerlink" title="Linux 编译OpenCV"></a>Linux 编译OpenCV</h2><h3 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h3><ol>
<li>安装类库<br>sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev</li>
</ol>
<p>sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev</p>
<ol start="2">
<li>cmake</li>
</ol>
<p>cmake  -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DOPENCV_GENERATE_PKGCONFIG=ON ..</p>
<p>最后一个参数会生成 /usr/local/lib/pkgconfig</p>
<ol start="3">
<li><p>编译<br>make -j8</p>
</li>
<li><p>安装<br>make install</p>
</li>
</ol>
<h3 id="pkgconfig-运行"><a href="#pkgconfig-运行" class="headerlink" title="pkgconfig 运行"></a>pkgconfig 运行</h3><p>默认情况,pkg-config首先在 /usr/lib/pkgconfig/ /usr/local/lib/pkgconfig 查找xxx.pc<br>没有的话在 PKG_CONFIG_PATH</p>
<p>pkg-config –libs –cflags opencv<br>查看gcc的CFLAGS参数</p>
<h3 id="Linux-变量"><a href="#Linux-变量" class="headerlink" title="Linux 变量"></a>Linux 变量</h3><p>C_INCLUDE_PATH      C 头文件<br>CPLUS_INCLUDE_PATH  C++ 头文件<br>LD_LIBRARY_PATH     动态链接库路径<br>LIBRARY_PATH        静态库的路径</p>
<h3 id="运行opencv"><a href="#运行opencv" class="headerlink" title="运行opencv"></a>运行opencv</h3><ol>
<li>直接指定 -I —L -l<br>g++ test.cpp -I /usr/local/include/opencv4 -lopencv_features2d -lopencv_calib3d -opencv_imgproc -lopencv_core -lopencv_highgui -lopencv_imgcodecs -o test</li>
</ol>
<p>缺少lib可以用下面的方法<br>nm -A lib64/libopencv*.a |grep “头文件”</p>
<ol start="2">
<li><p>pkg-config<br>pkg-config –help<br>pkg-config –modversion opencv4<br>g++ test.cpp <code>pkg-config --libs --cflags opencv4</code><br>生成a.out</p>
</li>
<li><p>cmake   CMakeList.txt<br>cmake_minimum_required(VERSION 2.8)<br>project(opencv)<br>set(OpneCV_DIR /path/to/opencv-x86/)<br>find_package(OpenCV REQUIRED)<br>add_executable(opencv try.cpp)<br>target_link_libraries(opencv ${OpenCV_LIBS})</p>
</li>
<li><p>动态链接库<br>/etc/ld.so.conf<br>include /etc/ld.so.conf.d/*.conf</p>
</li>
</ol>
<p>sudo ldconfig  </p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2019/07/16/linux-编译安装opencv/" data-id="ckbn4t15a0005t8tqtrh62qkq" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/linux/">linux</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/07/16/linux-启动流程/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          linux 启动流程
        
      </div>
    </a>
  
  
    <a href="/2019/07/14/Linux-查看版本/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Linux 查看版本</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/随笔/">随笔</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/hexo/">hexo</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/">linux</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/tips/">tips</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">标签云</h3>
    <div class="widget tagcloud">
      <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/linux/" style="font-size: 20px;">linux</a> <a href="/tags/tips/" style="font-size: 10px;">tips</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2019/07/">七月 2019</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2019/07/19/设置终端代理/">设置终端代理</a>
          </li>
        
          <li>
            <a href="/2019/07/16/linux-启动流程/">linux 启动流程</a>
          </li>
        
          <li>
            <a href="/2019/07/16/linux-编译安装opencv/">linux 编译安装opencv</a>
          </li>
        
          <li>
            <a href="/2019/07/14/Linux-查看版本/">Linux 查看版本</a>
          </li>
        
          <li>
            <a href="/2019/07/14/Debain版本/">Debain版本</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 零度可乐真好喝<br>
      <!-- Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> -->
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>